<template>
  <div>
    <el-container>
      <el-badge value="正在泡妞子" class="item" id="tututu"> </el-badge>
      <img src="../assets/4.jpeg" alt="" id="meimei" />
      <el-header @click="changeState">后台管理系统首页</el-header>
      <p id="name" @click="getUsers">
        {{ userinfo.username }}
      </p>
      <!-- <img src="../assets/19.jpg" alt="" class="photo" /> -->
      <!-- <img src="../assets/444.gif" alt=""> -->
      <span class="out" @click="outs" commit="userout">退出登录</span>
      <!-- 侧边栏 -->
      <el-container>
        <el-aside width="200px" height="900px">
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :unique-opened="true"
            :router="true"
          >
            <el-submenu
              :index="item.path"
              v-for="(item, index) in meunedata"
              :key="index"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item
                  :index="val.path"
                  v-for="(val, key) in item.children"
                  :key="key"
                  >{{ val.authName }}</el-menu-item
                >
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-container>
          <el-main>
            <router-view></router-view>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {},
      meunedata: [],
    };
  },
  methods: {
    //更新状态
    changeState() {
      this.$store.commit("increment");
      console.log(this.$store.state.counts);
    },
    //获取用户信息
    //获取token值,设置请求头,因为在axios分装了请求头，所以就不用设置了
    getUsers() {
      this.$req.get("users?pagenum=1&pagesize=1").then((serverBackData) => {
        const { data } = serverBackData.data;
        console.log(data);
      });
    },
    //退出登录
    outs(userout) {
      this.$message({
        message: "恭喜你，退出成功",
        type: "success",
      });
      localStorage.removeItem("userinfo");
      this.$router.push({ path: "/login" });
    },
  },

  async mounted() {
    //获取用户数据，转换为对象形式获取
    this.userinfo = JSON.parse(localStorage.getItem("userinfo"));

    //获取侧边栏数据，进行展示
    const { data, meta } = await this.$req.get("/menus");
    console.log(data.data);
    if (data.meta.status == 200) {
      this.meunedata = data.data;
    } else {
      this.$message.error(data.data.message);
    }
  },
};
</script>

<style>
#meimei {
  width: 50px;
  height: 50px;
  border-radius: 25px;
  position: absolute;
  top: 13px;
  left: 130px;
}

.out {
  width: 80px;
  height: 30px;
  position: absolute;
  right: 30px;
  top: 70px;
  background: yellow;
  /* display: none; */
}

#name {
  position: absolute;
  right: 50px;
}

#name:hover .out {
  display: block;
}

.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  height: 840px;
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
#tututu {
  position: absolute;
  left: 175px;
}
.photo {
  width: 80%;
  height: 80%;
  position: absolute;
  left: 240px;
  top: 150px;
}
</style>
